package com.longge;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-24 02:39
 */
public class Intersection {
    public int[] intersection(int[] nums1, int[] nums2) {

        HashSet<Integer> set = new HashSet<>();
        HashSet<Integer> res = new HashSet<>();
        for (int i : nums1) {
            set.add(i);
        }
        for (int i : nums2) {
            if (set.contains(i)){
                res.add(i);
            }
        }
        return res.stream().mapToInt(i->i).toArray();
    }
}
